﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;

namespace SilverlightCoverage
{
    public class CovPercentConverter : IValueConverter
    {

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            
            double minor = 0.0;
            string strMinor = string.Empty;
            if (value != null)
            {
                strMinor = value.ToString();
                minor = (100 - double.Parse(strMinor));                
            }
            return minor; 
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }


        //public int SetLblMajorWidth(double dblValue)
        //{
        //    int major = Convert.ToInt32(Math.Round(dblValue));
        //    return Convert.ToInt16((major / 2));
        //}
        //public int SetLblMinorWidth(double dblValue)
        //{
        //    int minor = (100 - (Convert.ToInt32(Math.Round(dblValue))));
        //    return Convert.ToInt16((minor / 2));
        //}



        #endregion
    }

    public class CovPercentStringConverter : IValueConverter
    {

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string strPercent = string.Empty;
            if (value != null)
            {
                strPercent = string.Format("{0:0.##}", value);                
            }
            return strPercent + "%";
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

    public class CovPercentColorConverter : IValueConverter
    {

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
             
            string covValue = value.ToString();
            string colorCode = string.Empty;
            if (value != null)
            {
                double covPercent = double.Parse(covValue);
                if (covPercent < 75.0)
                {
                    colorCode = "#FF0000";
                }               
            }
            return colorCode;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
    public class MethodNameStripConverter : IValueConverter
    {

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string strValue = string.Empty;
            string finalString = string.Empty;
            if (value != null)
            {
                strValue = value.ToString();
                if (strValue.Length > 90)
                {
                    finalString = strValue.Substring(0, 90);
                    finalString = finalString + "...";
                }
                else
                {
                    finalString = strValue; 
                }
            }
            return finalString;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
